package com.ternnetwork.core.configuration.repository;

import java.util.List;

import javax.persistence.LockModeType;

import org.springframework.data.jpa.repository.Lock;
import org.springframework.data.jpa.repository.Query;

import com.ternnetwork.persistence.repository.BaseRepository;
import com.ternnetwork.core.configuration.entity.Seq;


public interface SeqRepository extends BaseRepository<Seq, Long> {
	
	@Query("from Seq where name=?1")
	List<Seq> findAllByName(String name);
	
	@Lock(value = LockModeType.PESSIMISTIC_WRITE)  
	@Query("from Seq where name=?1")
	List<Seq> findAllAndLockByName(String name);
	
	@Query("select count(1) from Seq where name=?1")
	Long getCountByName(String name);
		
	@Query("select count(1) from Seq where name=?1 and id!=?2")
	Long getCountByNameAndExcludeId(String name,Long excludeId);
}
